<template>
  <a-drawer
    :title="title"
    :width="width"
    placement="right"
    :closable="false"
    @close="close"
    :visible="visible">
  
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item label="姓名" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'xingMing', validatorRules.xingMing]" placeholder="请输入姓名"></a-input>
        </a-form-item>
        <a-form-item label="性别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['xingBie', validatorRules.xingBie]" :trigger-change="true" dictCode="gkak_xb" placeholder="请选择性别"/>
        </a-form-item>
        <a-form-item label="日期" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-date placeholder="请选择日期" v-decorator="[ 'riQi', validatorRules.riQi]" :trigger-change="true" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="年龄" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'nianLing', validatorRules.nianLing]" placeholder="请输入年龄" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="电话" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'dianHua', validatorRules.dianHua]" placeholder="请输入电话"></a-input>
        </a-form-item>
        <a-form-item label="地址" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'diZhi', validatorRules.diZhi]" placeholder="请输入地址"></a-input>
        </a-form-item>
        <a-form-item label="就诊医院" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jiuZhenYiYuan', validatorRules.jiuZhenYiYuan]" placeholder="请输入就诊医院"></a-input>
        </a-form-item>
        <a-form-item label="就诊科室" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jiuZhenKeShi', validatorRules.jiuZhenKeShi]" placeholder="请输入就诊科室"></a-input>
        </a-form-item>
        <a-form-item label="门诊病历号" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'bingLiHao', validatorRules.bingLiHao]" placeholder="请输入门诊病历号"></a-input>
        </a-form-item>
        <a-form-item label="就诊医生" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jiuZhenYiSheng', validatorRules.jiuZhenYiSheng]" placeholder="请输入就诊医生"></a-input>
        </a-form-item>
        <a-form-item label="配药" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'peiYao', validatorRules.peiYao]" placeholder="请输入配药"></a-input>
        </a-form-item>
        <a-form-item label="金额" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input-number v-decorator="[ 'jinE', validatorRules.jinE]" placeholder="请输入金额" style="width: 100%"/>
        </a-form-item>
        <a-form-item label="分类" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['fenLei', validatorRules.fenLei]" :trigger-change="true" dictCode="gkak_fl" placeholder="请选择分类"/>
        </a-form-item>
        <a-form-item label="患病部位" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="list" v-decorator="['huanBingBuWei', validatorRules.huanBingBuWei]" :trigger-change="true" dictCode="gkak_hbbw" placeholder="请选择患病部位"/>
        </a-form-item>
        <a-form-item label="检查内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jianChaNeiRong', validatorRules.jianChaNeiRong]" placeholder="请输入检查内容"></a-input>
        </a-form-item>
        <a-form-item label="主诉内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'zhuSuNeiRong', validatorRules.zhuSuNeiRong]" placeholder="请输入主诉内容"></a-input>
        </a-form-item>
        <a-form-item label="既往史" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jiWangShi', validatorRules.jiWangShi]" placeholder="请输入既往史"></a-input>
        </a-form-item>
        <a-form-item label="现病史" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'xianBingShi', validatorRules.xianBingShi]" placeholder="请输入现病史"></a-input>
        </a-form-item>
        <a-form-item label="检查结果" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'jianChaJieGou', validatorRules.jianChaJieGou]" placeholder="请输入检查结果"></a-input>
        </a-form-item>
        <a-form-item label="费别" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-dict-select-tag type="radio" v-decorator="['feiBie', validatorRules.feiBie]" :trigger-change="true" dictCode="gkak_fb" placeholder="请选择费别"/>
        </a-form-item>
        <a-form-item label="诊断" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'zhenDuan', validatorRules.zhenDuan]" placeholder="请输入诊断"></a-input>
        </a-form-item>
        <a-form-item label="治疗处方" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'zhiLiaoChuFang', validatorRules.zhiLiaoChuFang]" placeholder="请输入治疗处方"></a-input>
        </a-form-item>
        <a-form-item label="相关禁忌" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <a-input v-decorator="[ 'xiangGuanJinJi', validatorRules.xiangGuanJinJi]" placeholder="请输入相关禁忌"></a-input>
        </a-form-item>
        <a-form-item label="图片" :labelCol="labelCol" :wrapperCol="wrapperCol">
          <j-upload v-decorator="['fuJian', validatorRules.fuJian]" :trigger-change="true"></j-upload>
        </a-form-item>
        
      </a-form>
    </a-spin>
    <a-button type="primary" @click="handleOk">确定</a-button>
    <a-button type="primary" @click="handleCancel">取消</a-button>
  </a-drawer>
</template>

<script>

  import { httpAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import { validateDuplicateValue } from '@/utils/util'
  import JDate from '@/components/jeecg/JDate'  
  import JUpload from '@/components/jeecg/JUpload'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"
  
  export default {
    name: "GkakDaDianZiBingLiModal",
    components: { 
      JDate,
      JUpload,
      JDictSelectTag,
    },
    data () {
      return {
        form: this.$form.createForm(this),
        title:"操作",
        width:800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
          xingMing: {rules: [
            {required: true, message: '请输入姓名!'},
          ]},
          xingBie: {rules: [
          ]},
          riQi: {rules: [
          ]},
          nianLing: {rules: [
          ]},
          dianHua: {rules: [
          ]},
          diZhi: {rules: [
          ]},
          jiuZhenYiYuan: {rules: [
            {required: true, message: '请输入就诊医院!'},
          ]},
          jiuZhenKeShi: {rules: [
            {required: true, message: '请输入就诊科室!'},
          ]},
          bingLiHao: {rules: [
          ]},
          jiuZhenYiSheng: {rules: [
            {required: true, message: '请输入就诊医生!'},
          ]},
          peiYao: {rules: [
          ]},
          jinE: {rules: [
          ]},
          fenLei: {rules: [
            {required: true, message: '请输入分类!'},
          ]},
          huanBingBuWei: {rules: [
            {required: true, message: '请输入患病部位!'},
          ]},
          jianChaNeiRong: {rules: [
          ]},
          zhuSuNeiRong: {rules: [
          ]},
          jiWangShi: {rules: [
          ]},
          xianBingShi: {rules: [
          ]},
          jianChaJieGou: {rules: [
          ]},
          feiBie: {rules: [
          ]},
          zhenDuan: {rules: [
          ]},
          zhiLiaoChuFang: {rules: [
          ]},
          xiangGuanJinJi: {rules: [
          ]},
          fuJian: {rules: [
          ]},
        },
        url: {
          add: "/gkakDaDianZiBingLi/add",
          edit: "/gkakDaDianZiBingLi/edit",
        }
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'xingMing','xingBie','riQi','nianLing','dianHua','diZhi','jiuZhenYiYuan','jiuZhenKeShi','bingLiHao','jiuZhenYiSheng','peiYao','jinE','fenLei','huanBingBuWei','jianChaNeiRong','zhuSuNeiRong','jiWangShi','xianBingShi','jianChaJieGou','feiBie','zhenDuan','zhiLiaoChuFang','xiangGuanJinJi','fuJian'))
        })
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            let formData = Object.assign(this.model, values);
            console.log("表单提交数据",formData)
            httpAction(httpurl,formData,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
              that.close();
            })
          }
         
        })
      },
      handleCancel () {
        this.close()
      },
      popupCallback(row){
        this.form.setFieldsValue(pick(row,'xingMing','xingBie','riQi','nianLing','dianHua','diZhi','jiuZhenYiYuan','jiuZhenKeShi','bingLiHao','jiuZhenYiSheng','peiYao','jinE','fenLei','huanBingBuWei','jianChaNeiRong','zhuSuNeiRong','jiWangShi','xianBingShi','jianChaJieGou','feiBie','zhenDuan','zhiLiaoChuFang','xiangGuanJinJi','fuJian'))
      }
      
    }
  }
</script>

<style lang="less" scoped>
/** Button按钮间距 */
  .ant-btn {
    margin-left: 30px;
    margin-bottom: 30px;
    float: right;
  }
</style>